/**
 * @file test.as

17.09.12 15:01:16
1、主屏没有轮播图片；
2、椭圆轮播的数量再增加2张；数量用配置文件；
3、照片墙展示由目前的3*5改成4*6共24张；用配置文件；
4、做2个版本软件：一个版本不带二维码和打印。一个版本带二维码和打印功能。用配置文件来显示或隐藏二维码功能；






 1、点击拍照后，倒计时5秒后再拍照。相框内依次出现5,4,3,2,1数字；
 2、轮播的照片数量增加或者图片放大；
 3、轮播照片方式加一种，照片铺满整个版面停留10秒钟（提供参考图）；
 4、统计界面加一个返回键（提供psd）
 沉禅  15:38:17
 原先的轮播效果加两张图片

 * @author db0@qq.com
 * @version 1.0.1
 * @date 2017-09-11
 */
package zhenbang
{
	import flash.display.Bitmap;
	import flash.geom.Rectangle;
	import flash.display.BitmapData;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.desktop.NativeApplication;
	import flash.events.KeyboardEvent;
	import flash.display.StageDisplayState;
	import flash.ui.Keyboard;
	import flash.events.MouseEvent;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	import flash.utils.getTimer;
	//CONFIG::debugging{ [SWF(width="600",height="400",frameRate="12",backgroundColor=0xeeeeee)] }
	[SWF(width="1920",height="1080",frameRate="12",backgroundColor=0xeeeeee)] 
		public class test extends Sprite
		{
			private static var _stageW:int;
			private static var _stageH:int;
			private static var _main:test;

			public static function get main():test
			{
				return _main;
			}
			public static function get stageW():int
			{
				return _stageW;
			}
			public static function get stageH():int
			{
				return _stageH;
			}
			public function test()
			{
				_main = this;

				if(stage)init(null);
				else addEventListener(Event.ADDED_TO_STAGE,init);
			}

			private static var _startTime:uint;
			public static function get startTime():uint
			{
				return _startTime;
			}
			public static function get now():uint
			{
				return getTimer();
			}
			public static function get passedTime():uint
			{
				return now - startTime;
			}

			private function init(e:Event):void
			{
				removeEventListener(Event.ADDED_TO_STAGE,init);
				//addChild(new logs);
				_stageW = stage.stageWidth;
				_stageH = stage.stageHeight;


				SwfLoader.SwfLoad("asset/bg.jpg",loaded);

				CONFIG::debugging{ return; }
				//stage.align = StageAlign.topLeft;
				stage.scaleMode = StageScaleMode.EXACT_FIT;
				stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
				//stage.displayState = StageDisplayState.NORMAL;
			}

			public static function key_events(e:KeyboardEvent):void
			{
				switch(e.keyCode){
					case Keyboard.BACK:
					case Keyboard.ESCAPE:
					case Keyboard.F4:
					case Keyboard.TAB:
						e.preventDefault();
						logs.adds("ESCAPE");
						CONFIG::debugging{
							NativeApplication.nativeApplication.exit();
						}
						PassWordInput.show();
						Toast.show("确认退出");
						break;
				}
			}

			private var _bg:Bitmap = null;
			public function get bg():Bitmap
			{
				if(_bg == null)
					return new Bitmap(new BitmapData(1920,1800));
				return _bg;
			}
			private function loaded(e:Event):void
			{
				if(e && e.type == Event.COMPLETE)
				{
					_bg = e.target.content as Bitmap;
					if(_bg==null)
						logs.adds("null Bitmap");
				}else{
					logs.adds(e);
				}
				Datas.init();

				stage.addEventListener(MouseEvent.MOUSE_UP,resetClock);
				stage.addEventListener(MouseEvent.MOUSE_DOWN,resetClock);
				stage.addEventListener(MouseEvent.MOUSE_MOVE,resetClock);
				NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, key_events);

				_startTime = now;

				backToFirstPage();
				//addChild(new Server()); 

				Window2.show();
				stage.nativeWindow.alwaysInFront = true;

				/*
				   CONFIG::debugging{
				   addChild(new PhotoPlayer());
				   return;
				   }
				 */
			}

			private var showPswdTimeoutId:uint;
			private var timesClicked:int = 0;

			private var timeoutId:uint;
			private function resetClock(e:MouseEvent):void
			{
				clearTimeout(timeoutId);
				timeoutId = setTimeout(backToFirstPage,30*1000);

				if(e.type == MouseEvent.MOUSE_UP && mouseX<stageW/10 && mouseY < stageH/10)
				{
					if(PassWordInput.main.visible)
						return;
					timesClicked++;
					if(timesClicked>3)
					{
						clearTimeout(showPswdTimeoutId);
						PassWordInput.show();
						timesClicked = 0;
					}else if(timesClicked==1){
						showPswdTimeoutId = setTimeout(reset5s,5000);
					}
				}
			}
			private function reset5s():void
			{
				clearTimeout(showPswdTimeoutId);
				timesClicked=0;
			}

			private function backToFirstPage():void
			{
				clearTimeout(timeoutId);
				FirstPage.show();
				PassWordInput.main.visible = false;
			}


			public static function newBtn(s:String,fun:Function=null):TxtBtn
			{
				var btn:TxtBtn = new TxtBtn(s,fun);
				btn.setformat(new Rectangle(0,0,300,100),0x990000,0x990000,0xffffff,0xffffff,0xee9900);
				return btn;
			}


		}
}
